<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:54:"E:\WWW\waimai/app/admin/shop\view\shop_goods\edit.html";i:1501496315;s:53:"E:\WWW\waimai/app/admin/index\view\template\base.html";i:1495522842;}*/ ?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href="__STATIC__/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <!--图标字体元件库-->
    <link rel="stylesheet" href="__STATIC__/plugins/font-awesome4.5.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="__STATIC__/admin/css/AdminLTE.min.css">
    <link rel="stylesheet" href="__STATIC__/admin/css/jquery.datetimepicker.css">
    <link rel="stylesheet" href="__STATIC__/admin/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="__STATIC__/plugins/validform/5.3.2/css/Validateform_v5.3.2.css">

    <link rel="stylesheet" href="__STATIC__/plugins/bootstrap-table/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/polaris/polaris.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/futurico/futurico.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/line/_all.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/square/_all.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/flat/_all.css">
    <link rel="stylesheet" href="__STATIC__/plugins/iCheck/minimal/_all.css">
    
<style>
    .nav-tabs-custom .nav-tabs{
        min-height: 100%;
        float: left;
        width: 10%;
    }
    .nav-tabs-custom .nav-tabs li{
        float: none;
        width: 100%;
    }
    .nav-tabs-custom .tab-content{
        width: 85%;
        float: left;
    }
    .nav-tabs-custom > .nav-tabs > li.active {
        border-top-color: #fff;
        border-right-color: #00a0e9;
    }
    .nav-tabs-custom > .nav-tabs > li.active a {
        border-right-color: transcategory;
        color: #00a0e9 ;
    }
    .btn-botom{
        height: 50px;
        margin-right: 20px;
        text-align: right;
        position: fixed;
        bottom:0;
        right:0;

    }
</style>
<link rel="stylesheet" href="__STATIC__/plugins/bootstrap-treeview/bootstrap-treeview.min.css">
<link href="__STATIC__/plugins/webuploader/custom/style.css" rel="stylesheet" type="text/css"/>
<!--<link rel="stylesheet" href="__STATIC__/plugins/select2/css/select2.min.css">-->


    <title><?php echo \think\Config::get('site.title'); ?></title>
    

    <script src="__STATIC__/plugins/jquery/jquery-3.0.0.min.js"></script>
    <script src="__STATIC__/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script src="__STATIC__/admin/js/app.min.js"></script>
    <script src="__STATIC__/admin/extend/app.js"></script>

    <script src="__STATIC__/admin/extend/H-ui.admin.js"></script>
    <script src="__STATIC__/plugins/layer3.0.3/layer.js"></script>
    <script src="__STATIC__/plugins/validform/5.3.2/Validform_v5.3.2_min.js"></script>

    <script src="__STATIC__/plugins/bootstrap-table/bootstrap-table.min.js" type="text/javascript"></script>
    <script src="__STATIC__/plugins/bootstrap-table/bootstrap-table-zh-CN.js" type="text/javascript"></script>

    <script src="__STATIC__/plugins/iCheck/icheck.min.js"></script>
    <script>

        var admin_menu_data=<?php if(isset($admin_menu)): ?><?php echo $admin_menu; endif; ?>;
        $(function () {
            $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
                checkboxClass: 'icheckbox_minimal-blue',
                radioClass: 'iradio_minimal-blue'
            });
        })
    </script>

    
<script src="__STATIC__/plugins/bootstrap-treeview/bootstrap-treeview.min.js"></script>
<!--<script src="__STATIC__/plugins/select2/js/select2.full.min.js"></script>-->
<!--<script src="__STATIC__/plugins/select2/js/i18n/zh-CN.js"></script>-->

</head>
<body class="hold-transition skin-blue-light sidebar-mini">
    
<div class="wrapper">
    <div class="nav-tabs-custom">
        <ul class="nav nav-tabs">
            <!--<li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="false">基本信息</a></li>-->
            <!--<li class=""><a href="#tab_2" data-toggle="tab" aria-expanded="false">详情</a></li>-->
            <!--<li class=""><a href="#tab_3" data-toggle="tab" aria-expanded="false">图片</a></li>-->
            <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="false">基本信息</a></li>
            <li class=""><a href="#tab_2" data-toggle="tab" aria-expanded="false">商品规格</a></li>
            <li class=""><a href="#tab_3" data-toggle="tab" aria-expanded="false">详情</a></li>
            <li class=""><a href="#tab_4" data-toggle="tab" aria-expanded="false">图片</a></li>
        </ul>
        <form id="form" class="form-horizontal" action="<?php echo url('ShopGoods/update'); ?>">
            <div class="tab-content">
                <div class="tab-pane active" id="tab_1">
                    <div class="box-body">
                        <input type="hidden" id="id" name="id" value="<?php echo $data['id']; ?>"/>
                        <div class="form-group">
                            <label class="col-sm-2 control-label"><span style="color: red;">*</span>对应商家</label>
                            <div class="col-sm-6">
                                <select id="sel_store" name='store_id' class="form-control select2" datatype="*"
                                        nullmsg="请选择对应商家">
                                    <?php if(is_array($store['rows']) || $store['rows'] instanceof \think\Collection || $store['rows'] instanceof \think\Paginator): $i = 0; $__LIST__ = $store['rows'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                                    <option value="<?php echo $vo['id']; ?>"><?php echo $vo['text']; ?></option>
                                    <?php endforeach; endif; else: echo "" ;endif; ?>
                                </select>
                            </div>
                            <div class="col-sm-2"></div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label"><span style="color: red;">*</span>商品分类</label>
                            <div class="col-sm-6">
                                <select id="sel_category" name='category_tree' class="form-control select2" datatype="*"
                                        nullmsg="请选择分类">
                                    <?php if(is_array($category['rows']) || $category['rows'] instanceof \think\Collection || $category['rows'] instanceof \think\Paginator): $i = 0; $__LIST__ = $category['rows'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                                    <option value="<?php echo $vo['id']; ?>"><?php echo $vo['name']; ?></option>
                                    <?php endforeach; endif; else: echo "" ;endif; ?>
                                </select>
                            </div>
                            <div class="col-sm-2"></div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label"><span style="color: red;">*</span>商品名称</label>
                            <div class="col-sm-6">
                                <input class="form-control" type="text" name="name" value="<?php echo $data['name']; ?>"  datatype="*" nullmsg="请填写商品名称">
                            </div>
                            <div class="col-sm-2"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">商品简介</label>
                            <div class="col-sm-6">
                                <textarea name="intro" class="form-control" rows="3" maxlength="255"><?php echo $data['intro']; ?></textarea>
                            </div>
                            <div class="col-sm-2"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">原价</label>
                            <div class="col-sm-6">
                                <div class="input-group">
                                    <span class="input-group-addon">￥</span>
                                    <input name="price_original" value="<?php echo $data['price_original']; ?>" type="number" class="form-control" style="width: 100px;">
                                </div>
                            </div>
                            <div class="col-sm-2"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">价格</label>
                            <div class="col-sm-6">
                                <div class="input-group">
                                    <span class="input-group-addon">￥</span>
                                    <input name="price" type="number" value="<?php echo $data['price']; ?>" class="form-control" style="width: 100px;">
                                </div>
                            </div>
                            <div class="col-sm-2"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">销量</label>
                            <div class="col-sm-6">
                                <input class="form-control" type="number" name="sales" value="<?php echo $data['sales']; ?>"  style="width: 139px;">
                            </div>
                            <div class="col-sm-2"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">排序</label>
                            <div class="col-sm-6">
                                <input class="form-control" type="number" name="sort" style="width: 139px;" value="<?php echo $data['sort']; ?>">
                            </div>
                            <div class="col-sm-2"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">是否推荐商品</label>
                            <div class="col-sm-6"  style="margin-top: 7px">
                                <span class="mr20" style="padding-right: 20px"><input type="radio" class="minimal" name="is_rec" value="0"> 否</span>
                                <span class="mr20"><input type="radio" class="minimal" name="is_rec" value="1" > 是</span>
                            </div>
                            <div class="col-sm-2"></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">是否上架</label>
                            <div class="col-sm-6" style="margin-top: 7px">
                                <span class="mr20" style="padding-right: 20px"><input type="radio" class="minimal" name="flag_putaway" value="0" > 下架</span>
                                <span class="mr20" ><input type="radio" class="minimal" name="flag_putaway" value="1"> 上架</span>
                            </div>
                            <div class="col-sm-2"></div>
                        </div>
                    </div>

                </div>
                <!-- /.tab-pane -->
                <div class="tab-pane" id="tab_2">
                    <div class="box-body">
                        <?php if(is_array($variant['rows']) || $variant['rows'] instanceof \think\Collection || $variant['rows'] instanceof \think\Paginator): $i = 0; $__LIST__ = $variant['rows'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>
                        <div class="form-group" style="margin-bottom: 5px;">
                            <div class="col-sm-1"></div>
                            <div class="panel panel-default col-sm-6" style="margin-bottom:5px;">
                                <div class="panel-body">
                                    <div class="form-group">
                                        <input  type="hidden" value="<?php echo $vo['id']; ?>"  name="variant_id[]">
                                        <label class="col-sm-2 control-label"><span style="color: red;">*</span>型号</label>
                                        <div class="col-sm-6">
                                            <input class="form-control" type="text" name="variant_name[]" value="<?php echo $vo['name']; ?>" datatype="*" nullmsg="请填商品型号">
                                        </div>
                                        <div class="col-sm-2"></div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"><span style="color: red;">*</span>价格</label>
                                        <div class="col-sm-6">
                                            <div class="input-group">
                                                <span class="input-group-addon">￥</span>
                                                <input name="variant_price[]" type="number" class="form-control" min="0" value="<?php echo $vo['price']; ?>" style="width: 100px;" datatype="*" nullmsg="请填商品价格">
                                            </div>
                                        </div>
                                        <div class="col-sm-2"></div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-sm-1" ><a href="javascript:;" data-variant_id="<?php echo $vo['id']; ?>" onclick="remove_variant(this)"><i class="fa fa-trash-o" style="padding-top: 50%;padding-left: 50%;color: #f32310;"></i></a></div>
                        </div>
                        <?php endforeach; endif; else: echo "" ;endif; ?>
                        <div class="form-group">
                            <label class="col-sm-7 control-label"><a id="variant-add" href="javascript:;"><i class="fa fa-plus"></i>&nbsp;添加商品型号</a></label>
                        </div>
                    </div>
                </div>
                <div class="tab-pane" id="tab_3">
                    <div class="box-body">
                        <div class="form-group">
                            <div class="col-sm-22">
                                <!-- 加载编辑器的容器 -->
                                <script id="container1" name="detail" type="text/plain" style="height: 350px;border:none; width: 100%;"><?php echo $data['detail']; ?></script>
                                <!-- 配置文件 -->
                                <script type="text/javascript" src="__STATIC__/plugins/ueditor/ueditor.config.js"></script>
                                <!-- 编辑器源码文件 -->
                                <script src="__STATIC__/plugins/ueditor/ueditor.all.min.js" type="text/javascript"></script>
                                <!-- 实例化编辑器 -->
                                <script type="text/javascript">
                                    var ue = UE.getEditor('container1');
                                </script>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="tab-pane" id="tab_4">
                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">封面图片</label>
                            <div class="col-sm-10">
                                <div class="row">
                                    <div class="col-sm-6">
                                        <input id="simple" name="cover_image_id" type="hidden" value="<?php echo $data['cover_image']; ?>"/>
                                        <button type="button" class="btn btn-danger simple-upload">上传图片</button>
                                    </div>
                                    <div class="col-sm-6">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">商品幻灯图</label>
                            <div class="col-sm-10">
                                <div class="row">
                                    <div class="col-sm-6">
                                        <input  id="multiple" name="slide_image_id" type="hidden" value="<?php echo $data['slide_image']; ?>"/>
                                        <button type="button" class="btn btn-danger multiple-upload">上传图片</button>
                                    </div>
                                    <div class="col-sm-6">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="btn-botom">
                <button type="submit" class="btn btn-primary btn-submit">&nbsp;&nbsp;保存商品&nbsp;&nbsp;</button>
            </div>
            <input type='hidden' name='deleted_variant_ids'/>
        </form>
        <!-- /.tab-content -->
    </div>

</div>


</body>
<script src="__STATIC__/admin/js/skins_control.js"></script>
<script src="__STATIC__/admin/js/jquery.datetimepicker.js"></script>

<script>
    //已删除的型号id
    window.DeletedVariantIds = '';

    $("#sel_store").find("[value='<?php echo $data['store_id']; ?>']").attr("selected", true);
    $("#sel_category").find("[value='<?php echo $data['category_tree']; ?>']").attr("selected", true);
    $("[name='is_rec'][value='<?php echo isset($data['is_rec']) ? $data['is_rec'] :  '1'; ?>']").attr("checked", true);
    $("[name='flag_putaway'][value='<?php echo isset($data['flag_putaway']) ? $data['flag_putaway'] :  '1'; ?>']").attr("checked", true);


    $("#sel_store").on('change', function () {
        var url = "<?php echo url('ShopGoods/get_category'); ?>";
        var id = $(this).val();
        $.post(url, {store_id: id}, function (ret) {
            var listHTML = '';
            for (var i = 0; i < ret.rows.length; i++) {
                listHTML += '<option value="' + ret.rows[i].id + '">' + ret.rows[i].name + '</option>';
            }
            $('#sel_category').empty();
            $('#sel_category').append(listHTML);
        }, 'json');
    });

    $('.multiple-upload').on('click',function (e) {
        var ids=$("#multiple").val();
        layer_open('多图上传',"<?php echo url('/addons/web_uploader/upload/parent_ele/multiple/id/"+ids+"'); ?>",{w:"600px",h:"400px"})
    });
    $('.simple-upload').on('click',function (e) {
        var ids=$("#simple").val();
        layer_open('单图上传',"<?php echo url('/addons/web_uploader/upload/parent_ele/simple/id/"+ids+"'); ?>",{w:"600px",h:"400px"})
    });

    function get_id() {
        var id=$("#slide_image").val();
        alert(id);
    }


    $("#form").Validform({
        tiptype:2,
        showAllError:true,
        ajaxPost: true,
        postonce:true,
        beforeSubmit: function (curform) {
            // * 提交前处理数据

            //格式化已删除的型号id
            if(DeletedVariantIds.length >0 && DeletedVariantIds.indexOf(',',DeletedVariantIds.length-1) > 0){
                window.DeletedVariantIds = DeletedVariantIds.substring(0,DeletedVariantIds.length-1);
            }
            $("[name='deleted_variant_ids']").attr("value", DeletedVariantIds);
        },
        callback: function (res) {
            if (res.success == true){
                layer.msg(res.message, {time: 1000},function () {
                    layer_close();
                    parent.window.location.reload();
//                    parent.$('#table').bootstrapTable('refresh');
                });
            }else{
                layer.alert(res.message);
            }
        }
    });

    //增加商品型号
    $("#variant-add").on("click",function () {
        var variantHTML = '<div class="form-group" style="margin-bottom: 5px;">'
            +'<div class="col-sm-1"></div>'
            +'<div class="panel panel-default col-sm-6" style="margin-bottom:5px;">'
            +'<div class="panel-body">'
            +'<div class="form-group">'
            +'<label class="col-sm-2 control-label"><span style="color: red;">*</span>型号</label>'
            +'<div class="col-sm-6">'
            +'<input class="form-control" type="text" name="variant_name[]" datatype="*" nullmsg="请填商品型号">'
            +'</div>'
            +'<div class="col-sm-2"></div>'
            +'</div>'
            +'<div class="form-group">'
            +'<label class="col-sm-2 control-label"><span style="color: red;">*</span>价格</label>'
            +'<div class="col-sm-6">'
            +'<div class="input-group">'
            +'<span class="input-group-addon">￥</span>'
            +'<input name="variant_price[]" type="number" min="0" value="0" class="form-control" style="width: 100px;" datatype="*" nullmsg="请填商品价格">'
            +'</div>'
            +'</div>'
            +'<div class="col-sm-2"></div>'
            +'</div>'
            +'</div>'
            +'</div>'
            +'<div class="col-sm-1" ><a href="javascript:;" data-variant_id="-1" onclick="remove_variant(this)"><i class="fa fa-trash-o" style="padding-top: 50%;padding-left: 50%;color: #f32310;"></i></a></div>'
            +'</div>';
        $(this).parents(".form-group").before(variantHTML);
        goToElementPosition(this);
    });

    /**
     *删除商品型号
     */
    function remove_variant(e) {
        if(e.dataset.variant_id > 0){
            window.DeletedVariantIds += e.dataset.variant_id;
            window.DeletedVariantIds += ',';
        }
        console.log(DeletedVariantIds);


        $(e).parents(".form-group").remove()
    }

    /**
     *设置滚动条位置
     */
    function goToElementPosition(e) {
        var docScrollTop = $(e).offset().top;
        $("body,html").animate({ scrollTop:  docScrollTop}, 1000);
    }



</script>


</html>